package org.onion.pattern.kit.springtool.retry;

import cn.hutool.core.bean.BeanUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.retry.RetryCallback;
import org.springframework.retry.RetryContext;
import org.springframework.retry.RetryListener;

@Slf4j
public class VersionRetryListener implements RetryListener {

    @Override
    public <T, E extends Throwable> boolean open(RetryContext retryContext, RetryCallback<T, E> retryCallback) {
        Object label = null;

        try {
            label = BeanUtil.getProperty(retryCallback, "label");
        } catch (Throwable e) {
            log.warn("无法获取 label", e);
        }

        log.warn("【领域版本】冲突重试告警 label {} count {}", label, retryContext.getRetryCount());
        return true;
    }


    @Override
    public <T, E extends Throwable> void close(RetryContext retryContext, RetryCallback<T, E> retryCallback, Throwable throwable) {

    }

    @Override
    public <T, E extends Throwable> void onError(RetryContext retryContext, RetryCallback<T, E> retryCallback, Throwable throwable) {

    }

}
